package org.come.Jpanel;

import com.tool.ModerateTask.Hero;
import com.tool.ModerateTask.Task;
import com.tool.ModerateTask.TaskRoleData;
import com.tool.tcpimg.UIUtils;
import org.come.model.ActiveBase;
import org.come.until.CutButtonImage;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

public class ZhuShouTaskJpanel extends JPanel {
    private boolean slelct;
    private JLabel labCheckBox;
    private ActiveBase zhuShouBean;
    public ZhuShouTaskJpanel(ActiveBase zhuShouBean) {
        setPreferredSize(new Dimension(862, 411));
        setOpaque(false);
        setLayout(null);

        getLabCheckBox();
        this.zhuShouBean = zhuShouBean;
    }

    public JLabel getLabCheckBox() {
        if (labCheckBox == null) {
            labCheckBox = new JLabel();
            labCheckBox.setBounds(10,15,15,15);
            labCheckBox.addMouseListener(new MouseListener(){
                @Override
                public void mouseClicked(MouseEvent e) {
                    slelct = !slelct;
                }

                @Override
                public void mousePressed(MouseEvent e) {

                }

                @Override
                public void mouseReleased(MouseEvent e) {

                }

                @Override
                public void mouseEntered(MouseEvent e) {

                }

                @Override
                public void mouseExited(MouseEvent e) {

                }
            });
            add(labCheckBox);
        }
        return labCheckBox;
    }

    private int count;
    private ImageIcon iconBack;
    private ImageIcon iconCheckBox;
    private ImageIcon iconSlelct;
    @Override
    protected void paintComponent(Graphics g) {
        // TODO Auto-generated method stub
        super.paintComponent(g);

        if (iconBack == null) {
            iconBack = CutButtonImage.getImage("inkImg/background/S342.png", -1, -1);
        }
        g.drawImage(iconBack.getImage(), 0, 0, 468, 53, this);

        if (iconCheckBox == null) iconCheckBox = CutButtonImage.getImage("inkImg/button/14.png", -1, -1);
        g.drawImage(iconCheckBox.getImage(), 10, 15, 15, 15, this);
        if (slelct) {
            if (iconSlelct == null) iconSlelct = CutButtonImage.getImage("inkImg/button/13.png", -1, -1);
            g.drawImage(iconSlelct.getImage(), 10, 15, 15, 15, this);
        }
        Graphics2D g2 = (Graphics2D) g;
        g2.setFont(UIUtils.TEXT_FONT78);
        g2.setColor(UIUtils.COLOR_NAME5);
        g2.drawString(zhuShouBean.getaName(), 40, 30);
        g2.drawString("(已完成任务", 40 + zhuShouBean.getaName().length() * 14, 30);
        g2.setColor(UIUtils.COLOR_NAME3);
        int num = zhuShouBean.getNum();
        if (zhuShouBean.getValue() == 1) {
            Task task = Hero.getHero().getSetTask(zhuShouBean.getSid());//根据任务系列id 获取人物身上的任务
            if (task != null) {
                this.count = task.getTaskCount();
                num = task.getTaskSum();
            }
        } else {
            this.count = TaskRoleData.SumReceive(zhuShouBean.getSid(), 2);
        }
        String count = String.valueOf(this.count);
        g2.drawString(count, 120 + zhuShouBean.getaName().length() * 14, 30);
        g2.setColor(UIUtils.COLOR_NAME5);
        g2.drawString("次)", 120 + zhuShouBean.getaName().length() * 14 + count.length() * 9, 30);
        g2.setFont(UIUtils.TEXT_FONT78);
        g2.setColor(Color.WHITE);
        g2.drawString(num + "", 388, 29);
    }

    public boolean isSlelct() {
        return slelct;
    }

    public ActiveBase getZhuShouBean() {
        return zhuShouBean;
    }
}
